import { reactive } from 'vue'
interface IState {
  group_id: number | undefined
  node_status: number
  tcc_status: number
  fieldStatus: number
  ip?: string //节点ip
  name?: string //节点名称
  tcc_version?: string //tcc包版本
  kernel_version?: string //内核版本
  offset: number
  limit: number
}
export const state = reactive<IState>({
  group_id: 0,
  node_status: 0,
  tcc_status: 0,
  name: '',
  fieldStatus: 1,
  ip: '',
  kernel_version: '',
  tcc_version: '',
  offset: 0,
  limit: 20
})
interface IGroupState {
  fieldStatus: number
  name: string
  remark: string
  offset: number
  limit: number
}
export const groupState = reactive<IGroupState>({
  fieldStatus: 1,
  name: '',
  remark: '',
  offset: 0,
  limit: 20
})
export interface IStatus {
  record: any
  visible: boolean
}
export const status_state = reactive<IStatus>({
  record: {} as any,
  visible: false
})
export const multipleSelection = ref<string[]>([])
export const groupMultipleSelection = ref<string[]>([])
export const TCC_STATUS: Record<number, any> = {
  0: '全部',
  1: '启用',
  2: '禁用',
  3: '未安装'
}
export const TCC_STATUS_LIST: Record<number, any> = [
  { value: 0, label: '全部TCC状态' },
  { value: 1, label: '启用' },
  { value: 2, label: '禁用' },
  { value: 3, label: '未安装' }
]
export const NODE_STATUS: Record<number, any> = {
  0: '全部',
  1: '在线',
  2: '离线'
}
export const NODE_STATUS_LIST: Record<number, any> = [
  { value: 0, label: '全部节点状态' },
  { value: 1, label: '在线' },
  { value: 2, label: '离线' }
]
export const BBR_STATUS: Record<number, any> = {
  1: '启用',
  2: '未启用'
}
export const STATUS_STYLE: Record<number, any> = {
  1: '#28B06F',
  2: '#FF833E ',
  3: '#EA2C2C'
}
export const OPERATION_LIST = [
  {
    value: 1,
    label: '节点名称'
  },
  {
    value: 2,
    label: '节点ip'
  },
  {
    value: 3,
    label: '内核信息'
  },
  {
    value: 4,
    label: 'TCC版本'
  }
]
export const OPERATION_DATA: Record<number, any> = {
  1: 'name',
  2: 'ip',
  3: 'kernel_version',
  4: 'tcc_version'
}
export const GROUP_OPERATION_LIST = [
  {
    value: 1,
    label: '分组名称'
  },
  {
    value: 2,
    label: '备注'
  }
]
export const GROUP_OPERATION_DATA: Record<number, any> = {
  1: 'name',
  2: 'remark'
}

export const resetFunc = () => {
  // let key: keyof IState
  // for (key in state) {
  //   state[key] = ''
  // }
  ;(state.group_id = 0),
    (state.node_status = 0),
    (state.tcc_status = 0),
    (state.name = ''),
    (state.fieldStatus = 1),
    (state.ip = ''),
    (state.kernel_version = ''),
    (state.tcc_version = ''),
    (state.offset = 0),
    (state.limit = 20)
}
export const groupResetFunc = () => {
  const keys = Object.keys(groupState) as (keyof Pick<
    IGroupState,
    'name' | 'remark'
  >)[]
  for (const key of keys) {
    groupState[key] = ''
    groupState.fieldStatus = 1
  }
}
